﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>字段列表</title>
	<link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="../../Comm/JScript.js"></script>
	<script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
	<script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../../Scripts/QueryString.js"></script>
	<script type="text/javascript" src="../../Scripts/config.js"></script>
	<base target="_self" />

	<script type="text/javascript" >
		/* ESC Key Down */
		function Esc() {
			if (event.keyCode === 27)
				window.close();
			return true;
		}

		//页面启动函数.
		$(function () {
		    $("#Msg").html("<img src=../../Img/loading.gif />&nbsp;正在加载,请稍后......");
			InitPage();
		});

		var FK_MapData;
		//初始化数据.
		function InitPage() {
			FK_MapData = GetQueryString("FK_MapData");
			//初始化表格.
			$.ajax({
			    type: 'post',
			    async: true,
			    url: Handler + "?DoType=FiledsList_Init&FK_MapData=" + FK_MapData + "&m=" + Math.random(),
			    dataType: 'html',
			    success: function (data) {

			        if (data.indexOf("err@") > -1) {
			            alert(data);
			            return;
			        }

			        //$("#Msg").html(data);	//for test
			        data = JSON.parse(data);
			        //增加处理.
			        var newRow;
			        var normalFieldRows, enumFieldRows, fkFieldRows;
			        for (var i in data) {
			            newRow = "";
			            /*<th>序号</th>
			            <th>字段名</th>
			            <th>中文名</th>
			            <th>类型</th>
			            <th>长度</th>
			            <th>关联</th>
			            <th>编辑</th>*/

			            newRow = "<tr ><td class=Idx>" + i + "</td>";
			            newRow += "<td>" + data[i].KeyOfEn + "</td>";
			            newRow += "<td>" + data[i].Name + "</td>";
			            newRow += "<td>" + GetMyDataTypeText(data[i].MyDataType) + "</td>";

			            switch (GetMyDataTypeText(data[i].MyDataType)) {
			                case "string": //string
			                case "date":
			                case "datetime":
			                    newRow += "<td>min=" + data[i].MinLen + ",max=" + data[i].MaxLen + "</td>";
			                    break;
			                default:
			                    newRow += "<td>...</td>";
			                    break;
			            }


			            newRow += "<td>" + data[i].UIRefKey + "</td>";
			            newRow += "<td>";

			            if (data[i].KeyOfEn == 'RDT' || data[i].KeyOfEn == 'OID') {
			                newRow += "系统字段";
			            } else {

			                newRow += "<a href=\"javascript:Edit('" +
								data[i].MyPK +
								"','" +
								data[i].LGType +
								"','" +
								data[i].KeyOfEn +
								"','" +
								data[i].UIBindKey +
								"')\"><img src='/WF/Img/Btn/Edit.gif' border=0 />编辑</a>";
			                newRow += "<a href=\"javascript:Delete('" +
								data[i].MyPK +
								"')\"><img src='/WF/Img/Btn/Delete.gif' border=0 />删除</a>";
			            }

			            newRow += "</td>";
			            newRow += "</tr>";


			            switch (data[i].LGType) {
			                case 0: //普通
			                    normalFieldRows += newRow;
			                    break;
			                case 1: //枚举
			                    enumFieldRows += newRow;
			                    break;
			                case 2: //外键
			                    fkFieldRows += newRow;
			                    break;
			                default:
			                    break;
			            }
			        }
			        $("#Table1 tr:last").after("<tr><th colspan='9'>普通字段</th></tr>");
			        $("#Table1 tr:last").after(normalFieldRows);
			        $("#Table1 tr:last").after("<tr><th colspan='9'>枚举字段</th></tr>");
			        $("#Table1 tr:last").after(enumFieldRows);
			        $("#Table1 tr:last").after("<tr><th colspan='9'>外键字段</th></tr>");
			        $("#Table1 tr:last").after(fkFieldRows);
			        $("#Msg").html("");

			    }
			});
		}
		//获取字段类型值（键）
		function GetMyDataTypeText(key) {
			switch (key) {
				case 1:
					return "string";
				case 2:
					return "int";
				case 3:
					return "float";
				case 4:
					return "boolean";
				case 5:
					return "double";
				case 6:
					return "date";
				case 7:
					return "datetime";
				case 8:
					return "money";
				default:
					return "unknow";
			}
		}

		//新建字段
		function New() {
			var url = "../FoolFormDesigner/FieldTypeList.htm?FK_MapData=" + FK_MapData;
			var w =window.showModalDialog(url, 'ass', 'dialogHeight: 500px; dialogWidth: 700px;center: yes; help: no');
			window.location.reload();
		}

		//编辑字段
		function Edit(no, type, KeyOfEn, EnumKey) {

		    var url;
		    if (type == 0) {
		        url = "../FoolFormDesigner/EditF.htm?MyPK=" + no + "&FK_MapData=" + FK_MapData + "&KeyOfEn=" + KeyOfEn;
		    }
		    else if (type == 1) {
		        url = "../FoolFormDesigner/EditEnum.htm?DoType=Edit&MyPK=" + no + "&FK_MapData=" + FK_MapData + "&KeyOfEn=" + KeyOfEn + "&EnumKey=" + EnumKey;
		    }
		    else if (type == 2) {
		        url = "../FoolFormDesigner/EditTable.htm?DoType=Edit&MyPK=" + no + "&FK_MapData=" + FK_MapData + "&KeyOfEn=" + KeyOfEn + "&FK_MapDtl=" + KeyOfEn;
		    } else {
		        //alert(typeof(type));
		        alert("字段类型错误！");
		        return;
		    }

		    var b = window.showModalDialog(url, 'ass', 'dialogHeight: 500px; dialogWidth: 700px;center: yes; help: no');
		    //WinOpen(url);	//for test
		    window.location.href = window.location.href;
		}

		//删除字段
		function Delete(no) {
		    if (window.confirm('您确定要删除吗？') == false)
		        return;
		    $.ajax({
		        type: 'post',
		        async: true,
		        url: Handler + "?DoType=FiledsList_Delete&FK_MapData=" + FK_MapData + "&MyPK=" + no + "&m=" + Math.random(),
		        dataType: 'html',
		        success: function (data) {

		            alert(data);
		            if (data.indexOf('err@') > -1) {
		                return;
		            } else {
		                window.location.reload();
		            }
		        }
		    });
		}
	 </script>
</head>
<body onkeypress="Esc()" >

<table id="Table1" style="width:95%">
<caption>字段列表  - <a href="javascript:New()">新增</a></caption>
	<tr>
		<th>序号</th>
		<th>字段名</th>
		<th>中文名</th>
		<th>类型</th>
		<th>长度</th>
		<th>关联</th>
		<th>编辑</th>
	</tr>
</table>

<div id="Msg"></div>

</body>
</html>
